import random


money = 5000
num = random.randint(0, 500)
i = 0
while 1:
    s = int(input("请输入您要的猜的0-500数字："))
    # 可添加异常处理
    if s > num:
        money -= 500
        i += 1
        if money <= 0:
            print("你没钱了，Bye")
            break
        print("大了！你还有", money)
    elif s < num:
        money -= 500
        i += 1
        if money <= 0:
            print("你没钱了，Bye")
            break
        print("小了！你还有", money)
    else:
        money += 3000
        print("恭喜，猜中!本轮幸运数字为：", num,  "你猜了", i + 1, "次", "奖励3000你还有", money)
        flag = input("继续输入1，按任意键退出：")
        if flag == "1":
            num = random.randint(0, 500)
            i = 0
            continue
        else:
            break
print("游戏结束！！！！！")
